var datatable;// 定义一个全局的dataTable
var attachChar;
var epsAttachChar;
var areaAttachChar;
var d;
$(function() {
	getList();
	$('#table tbody').on('mouseover', 'tr', function() {
		if ($(this).hasClass('selected')) {
			$(this).removeClass('selected');
		} else {
			datatable.$('tr.selected').removeClass('selected');
			$(this).addClass('selected');
		}
	});
	//图表  
	psLineChar = echarts.init(document.getElementById('psLine'));
	epsAttachChar = echarts.init(document.getElementById('epsAttachChar'));
	areaAttachChar = echarts.init(document.getElementById('areaAttachChar'));
})

function getList() {
	//var beginDate=$("#beginDate").val();
	//var endDate=$("#endDate").val();
	var funName=$("#funName").val();
	var state=$("#state").val();
	
	$("#table tbody tr").remove();
	if (datatable == undefined || datatable == "undefined" || datatable == null) {
	} else {
		datatable.fnDestroy();
	}
	datatable = $('#table').dataTable({
		"bPaginate" : true, // 翻页功能
		"bLengthChange" : false, // 改变每页显示数据数量
		"bFilter" : true, // 过滤功能
		"bSort" : true, // 排序功能
		"bInfo" : true,// 页脚信息
		"bAutoWidth" : false,// 自动宽度
		// "sPaginationType": "full_numbers",//显示分页的样式 还有simple_numbers等
//		"sScrollX" : "100%",
		"sScrollXInner" : "110%",
		"iDisplayLength" : 50,

		"bScrollCollapse" : true,
		"oLanguage" : {
			"sLengthMenu" : "每页显示 _MENU_条",
			"sZeroRecords" : "没有找到符合条件的数据",
			"sProcessing" : "&nbsp;&nbsp;&nbsp;&nbsp;查询中，请稍等...",
			"sInfo" : "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
			"sInfoEmpty" : "没有记录",
			"sInfoFiltered" : "(从 _MAX_ 条记录中过滤)",
			"sSearch" : "搜索：",
			"oPaginate" : {
				"sFirst" : "首页",
				"sPrevious" : "前一页",
				"sNext" : "后一页",
				"sLast" : "尾页"
			}
		},
		"bProcessing" : true,
		"bServerSide" : true,
		"sAjaxSource" : "../../sys/srfLog/getFunctionList",
		"fnServerData" : function(sSource, aoData, fnCallback) {
			$.ajax({
				"type" : "post",
				"contentType" : "application/x-www-form-urlencoded",
				"url" : sSource,
				"dataType" : "json",
				"data" : {
					"aoData" : JSON.stringify(aoData),
					//"beginDate" : beginDate,
					//"endDate" : endDate,
					"funName" : funName,
					"state" : state
				}, // 以json格式传递
				"success" : function(resp) {
					fnCallback(resp.pageDate);
					d=resp.allData;
				}
			});
		},
		columns : [ {
			data : "function_name",
			render:function(data, type, full){
			    /*return "<a href='../../sys/srfLog/log?funName=" + data + "'>"+data+"</a>";*/
			    return "<a href='#' style=\"text-decoration: underline;\" onclick=\"forwordLog('"
				+ data
				+ "')\"  >" + data + "</a>";
			}	
		}, {
			data : "status"
		},{
			data : "exec_interval"
		},{
			data : "partition_type"
		},{
			data : "exec_seq"
		},{
			data : "save_length"
		}], 
		"columnDefs":[
		{
			"targets": [6],
			"data":"function_name",
		    "render":function(data, type, row){
		    	return "<a href='../../sys/srfLog/updateFunStatus?funName=" +data+ "'>设置状态</a>"; 
		    }
		}]

	});
}

function forwordLog(data){
	var url = "/sys/srfLog/log?funName=" + data ;
	linkTab("后台过程日志", url);
}

function showPic(){
	var tab=$(".table-a");
	var pic=$("#pic");
	
	if(tab.is(":hidden")){
		tab.show();
		pic.hide();
	}else{
		tab.hide();
		pic.show();
		
		initAttachChar();
		initEpsAttachChar();
		initAreaAttachChar();
	}
}

function initAttachChar(){
	//查询  
	psLineChar.clear();
	psLineChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../businessAnalysis/attachment/getAttachChar?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"allData" : JSON.stringify(d)
		},
		success : function(data) {
			psLineChar.setOption(data, true);
			psLineChar.hideLoading();
		}
	});
}

function initEpsAttachChar(){
	//查询  
	epsAttachChar.clear();
	epsAttachChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../businessAnalysis/attachment/getEpsAttachChar?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"allData" : JSON.stringify(d)
		},
		success : function(data) {
			epsAttachChar.setOption(data, true);
			epsAttachChar.hideLoading();
		}
	});
}

function initAreaAttachChar(){
	//查询  
	areaAttachChar.clear();
	areaAttachChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../businessAnalysis/attachment/getAreaAttachChar?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"allData" : JSON.stringify(d)
		},
		success : function(data) {
			areaAttachChar.setOption(data, true);
			areaAttachChar.hideLoading();
		}
	});
}

function resetQueryForm(){
	$('#queryForm')[0].reset(); 
}

function exportExcel(){
	$.ajax({
		type : "POST",
		url : "../../businessAnalysis/attachment/exportBigDataExcel?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"allData" : JSON.stringify(d)
		},
		success : function(data) {
			alert(data.msgs);
		}
	});
}